package com.tm.seurity.handler;

import com.tm.result.Result;
import com.tm.result.ResultCode;
import com.tm.utils.ResponseUtil;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by lichuan on 2022-09-24.
 * 未登陆异常
 */
@Component
public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
        //TODO 处理未登陆异常
        System.out.println("处理未登陆异常");
        ResponseUtil.out(httpServletResponse, Result.error(ResultCode.NOT_TOKEN));
    }
}
